trigger trg_SLA on SLA__c (before update)
{
    Map<Id,SLA__c> slaMap = new Map<ID,SLA__c>();
    
    
    if(Trigger.isUpdate)
    {
        //For SLA Implementation Total SLA Age...
        for(SLA__c slaObject : Trigger.New)
        {
            if(slaObject.Actual_Start_Date_Time__c != null && slaObject.Actual_End_Date_Time__c != null)
            {
               if( ( slaObject.Actual_Start_Date_Time__c != Trigger.oldmap.get(slaObject.Id).Actual_Start_Date_Time__c  )  || (slaObject.Actual_End_Date_Time__c != Trigger.oldmap.get(slaObject.Id).Actual_End_Date_Time__c )  )        
               {
                   slaMap.put(slaObject.Id, slaObject); 
                
               }
            
            }
            
        
        }
    
    
    
    }
    
    
    
    if(slaMap.size() > 0)
    {
         // Assumes the BSC work hours are the default for the Org
        List<BusinessHours> businessHoursObjectList = new List<BusinessHours>([select id from businesshours where isDefault = true LIMIT 1]) ;

        if(businessHoursObjectList.size() > 0)
        {
            for(SLA__c slaObject : slaMap.values())
            {
                //Calculating the total age of the Business Hours...
                // Find the number of business hours milliseconds between startTime and endTime as
                // defined by the default business hours.  Will return a negative value if endTime is
                // before startTime, 0 if equal, positive value otherwise.
                slaObject.Total_SLA_Age__c = (BusinessHours.diff(businessHoursObjectList[0].id, slaObject.Actual_Start_Date_Time__c  , slaObject.Actual_End_Date_Time__c ) / (60 * 60 * 1000L) );
            
            
            }
        
        
        }
    }
    




}